#include "stringbad.h"
#include <iostream>
using std::cout;
using std::endl;


void call_by_reference(StringBad & s);
void call_by_value(StringBad s);

const char* outcall = "out of call - ";

/**
 * 默认的“copy构造函数”和“赋值运算符”的“浅复制”问题
 */
int main(int argc, char const *argv[])
{
    

    {
        StringBad s1("aaaaaaa");
        StringBad s2("bbbbbbb");
        StringBad s3("ccccccc");

        cout << s1 << endl;
        cout << s2 << endl;
        cout << s3 << endl;
        cout << "=========================================================" << endl << endl;

        call_by_reference(s1);
        cout << outcall << s1 << endl;

        call_by_value(s2);
        cout << outcall << s2 << endl;
        cout << "=========================================================" << endl << endl;

        StringBad sb = s3;
        cout << outcall << sb << endl;
        StringBad sbb;  // 调用默认构造函数
        sbb = s3;       // 使用赋值运算符
        cout << outcall << sbb << endl;

        cout << "Exiting the block" << endl;
    }

    cout << "End of main()" << endl;
    return 0;
}

void call_by_reference(StringBad & s)
{
    cout << "call by reference - " << s << endl;
}

void call_by_value(StringBad s)
{
    cout << "call by value - " << s << endl;
}